import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'package:ls_work/viewmodel/medecine/medical_prescription_detail_view_model.dart';
import 'package:ls_work/widgets/common_widget.dart';

import '../../net/response/medicine_advice/medical_prescroption_list_data.dart';
class MedicalPrescriptionDetailPage extends BaseStatefulMvvmWidget{
  MedicalPrescroptionListData item;

  MedicalPrescriptionDetailPage({required this.item});

  @override
  State<StatefulWidget> createState() => MedicalPrescriptionDetailState();

}

class MedicalPrescriptionDetailState extends BaseMvvmRefreshState<MedicalPrescriptionDetailViewModel,MedicalPrescriptionDetailPage>{
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: AppBar(
        title: Text('处方详情'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  Widget createScrollWidget() {
    var item = widget.item;
    return SingleChildScrollView(
      padding: EdgeInsets.symmetric(horizontal: 16,vertical: 12),
      child: Column(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  CommonText('${item.customerName??""}',textSize: 17,fontWeight: FontWeight.bold),
                  SizedBox(width: 10,),
                  CommonText('${item.bedNo??""}',textSize: 15),
                  SizedBox().setWeight(1),
                  CommonText('处方号：${item.prescriptionNo??""}',fontWeight: FontWeight.bold)
                ],
              ),
              SizedBox(height: 10,),
              CommonText('处方日期：${item.prescriptionDate??""}')
            ],
          ).addToContainer(
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: 6.borderRadius
            ),
            width: double.infinity,
            padding: EdgeInsets.symmetric(horizontal: 10,vertical: 10)
          ),

          SizedBox(height: 10,),
          ...List.generate((item.detailBeans??[]).length, (index) {
            var medicine = (item.detailBeans??[])[index];
            return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                CommonText('${medicine.drugCommonName}',fontWeight: FontWeight.bold),
                SizedBox(height: 10,),
                FunctionGrid(children: [
                  MedicineValue(name: '规格', value: '${medicine.drugSpecifications}'),
                  MedicineValue(name: '开药数量', value: '${medicine.quantity?.d}${medicine.maxUnitName}'),
                  MedicineValue(name: '用法', value: '${medicine.usageType}'),
                  MedicineValue(name: '用量', value: '${medicine.usageQuantity?.d}${medicine.minUnitName}'),
                  MedicineValue(name: '用药频率', value: '${medicine.usageFrequency??""}'),
                  MedicineValue(name: '入柜状态', value: '${medicine.intoStatusName??""}'),
                ].map((e) => Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    CommonText(e.name),
                    SizedBox(height: 4,),
                    CommonText(e.value,textColor: Colors.blue,fontWeight: FontWeight.bold)
                  ],
                )).toList(), count: 2,crossSpace: 10,mainSpace: 15,)
              ],
            ).addToContainer(
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: 6.borderRadius
                ),
                width: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: 10,vertical: 10)
            );
          }).insertWidget(SizedBox(height: 10,))
        ],
      ),
    );
  }

  @override
  MedicalPrescriptionDetailViewModel createViewModel() {
    return MedicalPrescriptionDetailViewModel(context);
  }



}